#!/usr/bin/env ruby

require 'rubygems'
require File.expand_path(File.dirname(__FILE__) + "/../lib/epic.rb")
require File.expand_path(File.dirname(__FILE__) + "/../lib/epic/client.rb")

when_ready { puts "connected! send messages to #{jid}" }
disconnected { puts "disconnecting!" }

users = []

when_ready do 
	p = Muc.pres($c['room'],jid.node)
	client.write_with_handler(p) do |m|
		item, status = Muc.xpath(m,'item'), Muc.xpath(m,'status')
		puts item
	end
end

presence '//ns:x', :ns => Muc::NS_USER do |m, res|
	user, role = m.from.to_s, Muc.xpath(res,"item")['role']
	role != 'none' ? users.push(user) : users.delete(user)
end


message do |m| 
	false if Muc.xpath(m,"x",Muc::NS_DELAY)
end
message :groupchat? do |m| 
	puts "2nd"
end



